package com.zzh.lib.click;


import android.view.View;

import com.zzh.lib.views.shine.ShineImageView;

/**
 * Created by zzh on 2023/4/16.
 *
 * @date: 2023/4/16 20:35
 * @email: zzh_hz@126.com
 * @author: zzh
 * @description: com.zzh.lib.click
 */
public class OnButtonClickListener implements View.OnClickListener {

    private final ShineImageView siv;
    protected boolean isCheckFastClick = false;

    protected long interval = 300L;
    private long lastClickTime = 0l;

    public OnButtonClickListener(ShineImageView siv) {
        this.siv = siv;
    }

    public void setListener(View.OnClickListener listener) {
        this.listener = listener;
    }

    View.OnClickListener listener;

    public OnButtonClickListener(ShineImageView siv, View.OnClickListener l) {
        this.siv = siv;
        listener = l;
    }

    @Override
    public void onClick(View view) {
        if (isCheckFastClick){
            if ((System.currentTimeMillis() - lastClickTime) > interval) {
                if (!siv.isChecked()) {
                    siv.setChecked(true);
                    siv.showAnim();
                } else {
                    siv.setChecked(false);
                    siv.setCancel();
                }
                siv.onListenerUpdate(siv.isChecked());
                if (listener != null) {
                    listener.onClick(view);
                }
            }
            lastClickTime = System.currentTimeMillis();
        } else {
            if (!siv.isChecked()) {
                siv.setChecked(true);
                siv.showAnim();
            } else {
                siv.setChecked(false);
                siv.setCancel();
            }
            siv.onListenerUpdate(siv.isChecked());
            if (listener != null) {
                listener.onClick(view);
            }
        }

    }
}
